package month1;

public class SearchInsert35_07 {
    public static void main(String[] args) {
        System.out.println(searchInsert(new int[]{1, 3, 5, 6}, 5));
    }

    static int searchInsert(int[] nums, int target) {
        int n = nums.length;
        int l = 0, r = n - 1, ans = n;
        while (l <= r) {
            int m = l + r >> 1;
            if (nums[m] >= target) {
                ans = m;
                r = m - 1;
            } else {
                l = m + 1;
            }
        }
        return ans;
    }
}
